<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Jiucheng
 *
 * @author dragon.hu add @2016.2.26
 */
require_once 'BaseChannel.php';

//九城
class Jiucheng implements BaseChannel 
{
	
	function __construct() 
	{
		//echo "construct";
	}

	//put your code here
	function android($data) 
	{
		$paymentKey="3badd94d3e65a6fc083c386a3e2526415975"; //秘钥
		$ret = $this->paymentCallBack($paymentKey, ANDROID);
		echo $ret;
	}

	function ios($data) 
	{
		$paymentKey=""; //秘钥
		$ret = $this->paymentCallBack($paymentKey, IOS);
		echo $ret;
	}

	function paymentCallBack($paymentKey, $platform)
	{
		$orderLog = new ChargeOrder();
		$orderLog->log("jiucheng", $_REQUEST);
		
		$order_id = $_REQUEST['order_id'];
		$product_id = $_REQUEST['product_id'];
		$price = $_REQUEST['price'];
		$game_uid = $_REQUEST['game_uid'];
		$u_id = $_REQUEST['u_id'];
		$xcs_order = $_REQUEST['xcs_order'];
		$game_id = $_REQUEST['game_id'];
		$sign = $_REQUEST['sign'];
		
		$mysign = $order_id."_".$product_id."_".$price."_".$game_uid."_".$u_id."_".$xcs_order."_".$game_id."_".$paymentKey;
		
		if($sign == md5($mysign))
		{ //验证通过
			 
			//进行发货
			if(false == $orderLog->recordOrder(STATUS_SUCCESS, $price, $order_id, "jiucheng", $platform,$xcs_order))
			{
				$ret="0001";
				$orderLog->log("jiucheng",array("order"=>$order_id,"money"=>$price,"serverresult"=>"faild"));
			}else 
			{
				//支付成功
				$ret="0000";
				$orderLog->log("jiucheng",array("order"=>$order_id,"money"=>$price,"serverresult"=>"success"));
			}
		} 
		else 
		{
			//"$sig验证失败"
			$ret="0001";
			$orderLog->log("jiucheng","  order:$order_id  sign error sign:$sign mysign:$mysign");
		}
		return $ret;
	}
	
}